$(document).ready(function(){
    $('#content').css('min-height',($(window).height()-126));
    $(".mobile_list dl").each(function(index){
        var dthei = $(this).find("dt").height();
        var ddhei = $(this).find("dd").height();
        if(ddhei > dthei){
            $(this).find("dt").css("height",ddhei);
            $(this).find("dt img").css("padding-top",(ddhei-80)/2);
        }
    });
    
    $(".choice dl ol li").on('click',function(){        
        $(this).parents("dl").find("li").removeClass("crumb");		
        $(this).addClass("crumb");
		$(this).parents("dl").addClass("crumb");        
		var select_value = $(this).attr("data-value");
		$(this).parents("dl").attr("select-value",select_value);	
		
        var len = $(".choice dl.radio").length;
        var len2 = $(".choice .radio.crumb").length;
		$(".choice dl.radio").show();
		$.each($(this).parents("dl").nextAll(),function(k,v){
		   if (!$(v).hasClass('crumb')) { 
			  $("html, body").animate({scrollTop: $(v).offset().top+ "px"}, 300, "swing");
			  return false;
		   }
		});
        $(".num em").html(len-len2);
        	if((len-len2) == 0){
				var res = [];
				$(".choice .radio.crumb").each(function(i,e) {
					var x = $(e).attr("select-value");
					res.push(x);				
				});	
			var x = 0;
			var price = parseInt($('#price').html());
			$.each(res,function(i,e){							
				x += parseInt(e);	
			});
			var result = price-x;
			result = result>0?result:0;
			$("input[name^='order_price']").val(result);
			
			var order = new Object();
			$(".choice .radio.crumb").each(function(i,e) {						
				var key = $(e).find("dt").html();
				var value = $(e).find(".crumb").html();
				order[key] = value;
			});				
			$("input[name^='order_json']").val(JSON.stringify(order));
			$("#is_lock").val(1);		
		
			$(".choice_bnt").show();
			$("#price_s").html(result);
			$(".num").hide();
        }else{
            $(".choice_bnt").hide();
            $(".num").show();
        } 
    });    
    $('.num a').click(function(){
        $.each($('.radio'),function(k,v){
            if (!$(v).hasClass('crumb')) { 
                  $("html, body").animate({scrollTop: $(v).offset().top+ "px"}, 700, "swing");
                  return false;
               }
        });
    });
    
   
	var headHeight=$("#head").height()+$("#content").height()-$(".num").height();
	var windowheight=$(window).height();
	var scrollheight= headHeight-windowheight+$(".num").height();
	var subanv=$(".num");
	if(headHeight > windowheight){
		subanv.addClass("fix"); 
	}else{ 
		subanv.removeClass("fix"); 
	}
	
	$(window).scroll(function(){ 
		if($(this).scrollTop()> scrollheight){ 
			subanv.removeClass("fix");
		} else{
			subanv.addClass("fix"); 
		}
	})
});